package com.example.spring_hello.controller;

import com.example.spring_hello.pojo.Person;
import com.example.spring_hello.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/hello")
public class HelloController {
    @RequestMapping("/one")
    @ResponseBody
    public String hello() {
        return "hello";
    }
    @RequestMapping("/two")
    @ResponseBody
    public User hello1() {
        User user = new User();
        user.setUserName("张三");
        user.setAge(10);
        return user;
    }
    @RequestMapping("/three")
    @ResponseBody
    public void hello2(Date date) {
        System.out.println(date);
    }
    /*produces = "application/json;charset=utf-8  可以解决使用@ResponseBody返回字符串数据中文乱码问题*/
    @RequestMapping(value="/four",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String hello3(String name) {
        System.out.println(name);
        return name;
    }
    @RequestMapping("/five")
    @ResponseBody
    public Person hello5() {
        Person person = new Person();
        person.setName("李四");
        person.setDate(new Date());
        return person;
    }
}
